home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / wstriprg.zip / STRIP.C < prev    next >
C/C++ Source or Header  |  1991-10-22  |  2KB  |  73 lines

  1. /* Program to strip those nasty WordStar 8th bits. */
  2. /* Written by Sgt Rich Gautier */
  3. #include <stdio.h>
  4. #include <io.h>
  5. #include <string.h>
  6.  
  7. void main(argc,argv)
  8. int argc;
  9. char *argv[];
  10. {
  11.     FILE *fp;
  12.     int a, flag = 2;
  13.     void usage();
  14.  
  15.     if(argc<2)
  16.        {
  17.        fprintf(stderr,"You didn't give me a filename!\n");
  18.        usage();
  19.        exit(1);
  20.        };
  21.  
  22.     if(argc == 3 && (strcmp(argv[2],"/r")))
  23.        {
  24.        fprintf(stderr,
  25.           "You put in two parameters, and /r was not the second one.\n");
  26.        usage();
  27.        exit(2);
  28.        };
  29.  
  30.     /* If only two arguments, use a bypass flag for some of the code */
  31.     if(argc == 2)
  32.        flag = 3;
  33.  
  34.     if(!(fp=fopen(argv[1],"r")))
  35.        {
  36.        fprintf(stderr,"Sorry, that file cannot be opened for read!\n");
  37.        exit(3);
  38.        };
  39.  
  40.     do      {
  41.         a=fgetc(fp);
  42.         if(a > 127)
  43.            a = a - 128;
  44.  
  45.         if(flag == 2)
  46.            {
  47.            if(a == 46)
  48.               flag = 1;
  49.            else
  50.               flag = 0;
  51.            };
  52.  
  53.         if(flag == 0 || flag == 3)
  54.            fprintf(stdout,"%c",a);
  55.  
  56.         if(a == 10 && flag != 3)
  57.            flag = 2;
  58.         }
  59.     while(!feof(fp));
  60.     fclose(fp);
  61.     fclose(stdout);
  62.     exit();
  63. }
  64.  
  65. void usage()
  66. {
  67.     fprintf(stderr,"The command strip uses the following syntax:\n");
  68.     fprintf(stderr,"[d:][\path\]strip filespec [/r]\n");
  69.     fprintf(stderr,"The /r is used to delete all lines starting with a period(.)\n");
  70.     fprintf(stderr,"Program output may be directed via the > and >> symbols\n");
  71.     fprintf(stderr,"provided by DOS.  Errors will not be affected.\n");
  72. }
  73.